@extends('admin.home.main')

@section('body')
<section id="main-content">
	  <section class="wrapper">
		<h3>后台用户添加</h3>
		<!-- BASIC FORM ELELEMNTS -->
		<div class="row mt">
		  <div class="col-lg-12">
			<div class="form-panel">
			  <form class="form-horizontal style-form" action="/admin/user/insert" method="post">
			  	<input type="hidden" id="_token" name="_token" value="{{csrf_token()}}">
				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">用户名</label>
				  <div class="col-sm-10">
					<input type="text" style="width:400px;" class="form-control" id="username" name="username" placeholder="请输入用户名" size="50">
				  </div>
				</div>

				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">请输入密码</label>
				  <div class="col-sm-10">
					<input type="password" style="width:400px;" class="form-control" id="passwd" name="passwd" placeholder="请输入密码" size="50">
				  </div>
				</div>

				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">再次输入密码</label>
				  <div class="col-sm-10">
					<input type="password" style="width:400px;" class="form-control" id="password" name="password" placeholder="请输入密码"  size="50">
				  </div>
				</div>

				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">姓名</label>
				  <div class="col-sm-10">
					<input type="text" style="width:400px;" class="form-control" id="name" name="name" placeholder="请输入姓名"  size="50">
				  </div>
				</div>

				<!-- <div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">邮箱</label>
				  <div class="col-sm-10">
					<input type="email" style="width:400px;" class="form-control" id="email" name="email" placeholder="请输入邮箱"  size="50">
				  </div>
				</div> -->
				
				<button type="button" id="save" class="btn btn-success">提交</button>
				<button type="reset" class="btn btn-primary">重置</button>
			  </form>
			</div>
		  </div>
		  <!-- col-lg-12-->
		</div>

		
	  </section>
	  <!-- /wrapper -->
	</section>
<script type="text/javascript">
	$('#save').click(function(){
		var _token = $('#_token').val(),
			username = $('#username').val(),
			_passwd  = $('#passwd').val(),
			_password = $('#password').val(),
			name = $('#name').val();

		if(!username){
			alert('请输入用户名');
			return false;
		}

		if(!_passwd || !_password){
			alert('请输入密码');
			return false;
		}else{
			if(_passwd != _password){
				alert('请输入相同的密码');
				return false;
			}
		}

		if(!name){
			alert('请输入姓名');
			return false;
		}

		$.ajax({
			url:'/admin/user/insert',
			type:'post',
			data:{'_token':_token,'username':username,'password':_passwd,'name':name},
			dataType:'json',
			success:function(msg){
				if(msg.code == 200){
					alert('添加成功');
					location.href="/admin/user/list";
				}else if(msg.code == 301){
					alert('账户已存在,请勿重复添加');
					location.reload();
				}else{
					alert('添加失败');
					location.reload();
				}
			}
		})
		
	})
</script>
@endsection